﻿using UnityEngine;
using System.Collections;
namespace Room
{
    public class RCMoveSimple : RCMoveBase
    {
        public RCMoveSimple(RoomCharactor owner)
            :base(owner)
        {
            type = MoveType.Simple;
        }

        Vector3 target;

        bool arrived;
        bool stoped;
        
        public override void DoStart()
        {
            arrived = true;
            stoped = true;
        }

        public override void Tick()
        {
            if (arrived)
                return;

            var delta = target - owner.transform.position;
            if (delta.sqrMagnitude > 0.01f)
            {
                delta=delta.normalized*0.1f;
owner.transform.position+=delta;
            }
            else
            {
                owner.transform.position=target;
                arrived = true;
                if(stoped)
                {
                    //owner.Stand();
                }
            }
                
        }

        public override void MoveTo(Vector3 to)
        {
            arrived = false;
            stoped = false;
            target = to;
            owner.transform.LookAt(target);
        }

        public override void StopTo(Vector3 to)
        {
            arrived = false;
            stoped = true;
            target = to;
            owner.transform.LookAt(target);
        }
    }

}

